home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-02 | 25.2 KB | 1,006 lines |
- /***
- * GestisciElOrd_v03.c
- *
- * Standard File Pattern.
- * © 1994-96 Francesco Cadili.
- *
- * 16/09/96 1st version (Francesco Cadili),
- * use the standard file pattern.
- *
- * File: "GestisciElOrd_v01.c"
- *
- * Visualizza un ElOrd di dati.
- * Note sulla versione:
- * 1) Bisogna gestire lo scroll mentre il mouse seleziona del testo fuori dal
- * campo TEedit.
- * 2) Bisogna gestire il doppio click.
- * 3) per ora l'array viene allocato dalla chiamata a AggiustaScroll.
- * (una volta allocato non viene più deallocato)
- * 4) per ora permette al più 99 titoli
- * 5) i contenuti degli array della maschera e del valore variano da 0..numMax - 1
- * (quando vengono visualizzati vengono incrementati di 1)
- * 6) Cambia la gestione del campo (quando clicco cancello/inserisco il prossimo)
- * 7) Richiede "\r" alla fine per funzionare correttamente.
- *
- ***/
-
- /***** Include standard *****/
- /* #include <MacHeaders> */
-
- /***** Include locali *****/
- #include <stdio.h>
- #include <Fonts.h>
- #include <Controls.h>
- #include <Menus.h>
- #include <QuickDraw.h>
- #include "CGestisciElOrd_v03.h"
- #include "stringUtility_v02.h"
- #include "Error.h" // usato per gestire gli errori
-
- /***** Define macro *****/
-
- /***** Define valori *****/
-
- #define noValue -1
- #define kStdFont systemFont
- #define kStdHeight 12
- #define noTitle -1
- #define ours(w) (w == theDialog)
- #define kmaxNumData 10
- #define kErrOutMemory 1
- #define kErrRisorse 2
- #pragma segment CGestisciElOrd
-
- /***** Typedef globali *****/
-
- /***** Funzioni esterne *****/
-
- /***** Variabili esterne *****/
-
- /***** Variabili globali *****/
-
- /***** Statiche globali *****/
-
- /***** Function prototyping *****/
-
- /*** constructor
- *
- ****/
- CdataDescRec::CdataDescRec(void)
- {
- TEH = NULL;
- }
-
- /*** destructor
- *
- ****/
- CdataDescRec::~CdataDescRec(void)
- {
- if (TEH != NULL)
- delete TEH;
- }
-
- /*** costructor
- *
- ***/
- CGestisciElOrd::CGestisciElOrd(void)
- {
- theDialog = NULL;
- numerazione = NULL;
- editLine = NULL;
- num = NULL;
- descField = NULL;
- }
-
- /***** Function prototyping *****/
-
- /*** costructor
- *
- ***/
- CGestisciElOrd::~CGestisciElOrd(void)
- {
- Dispose();
- }
-
- /*** result = Alloca(theDialog, TEitem, &backGround, nField, descField, fontNum, sizeNum, canModify)
- *
- * Alloca la struttura dati "gestElOrdRec" nello Heap.
- *
- * Par INPUT: 'theDialog' il puntatore al dialog,
- * 'TEitem' il numero di item del campo text edit,
- * 'CTRLitem' il numero di item del campo di scroll,
- * '*backGround' lo sfondo del campo text edit,
- * 'textFont' la fonte del campo text edit,
- * 'textHeight' l'altezza del campo text edit.
- * 'maxNumData' il numero massimo di campi ammassi.
- * Val OUTPUT: il puntatore alla struttura dati se tutto ok, NULL altrimenti.
- *
- **************************************************************************************/
- Boolean CGestisciElOrd::IGestisciElOrd(DialogPtr theDialog, short TEitem,
- RGBColor *backGround, short fontNum,
- short fontSize, short nField,
- CdataDescRec ***descField, Boolean canModify,
- Boolean hasScroll, Boolean hasNumberField)
- {
- short result = true;
-
- this->theDialog = theDialog;
- this->TEitem = TEitem;
- this->backGround = *backGround;
- maxNumData = kmaxNumData; // massimo 20elemnti
- this->hasNumberField = hasNumberField;
- this->nField = nField;
- this->descField = descField;
- this->canModify = canModify;
- if (InitData(fontNum, fontSize, hasScroll))
- { // errore nell'inizializzazione dei campi
- Dispose();
- SetErrorData(kErrOutMemory, 0, "Alloca", "inizializzazione della struttura dati", "");
- return(true);
- }
- else
- return(false);
- }
-
- /*** Dispose(&elOrdHdl)
- *
- * Dealloca la struttura dati "dataHdl".
- * Nota: da chiamare prima della deallocazione del
- * dialog (**elOrdHdl)->theDialog.
- *
- * Par INPUT: '*elOrdHdl' l' Handle del dialog.
- * Val OUTPUT: 'elOrdHdl' è posto a NULL.
- ****/
- void CGestisciElOrd::Dispose(void)
- {
- CdataDescRec **descPtr = NULL;
- short i;
-
- HLock((Handle)descField);
- descPtr = *descField;
- for (i = 0; i < nField; i++, descPtr++)
- if (descPtr != NULL)
- delete *descPtr;
- else
- break;
- HUnlock((Handle)descField);
-
- if (num != NULL)
- DisposHandle((Handle)num);
- if (editLine != NULL)
- delete editLine;
- }
-
- /*** "InitData(textFont, textHeight)"
- *
- * Inizializza i dati relativi al DLOG.
- * (Presuppone che i primi dati della struttura globale
- * siano presenti).
- *
- * Par INPUT: 'textFont' la fonte del campo text edit,
- * 'textHeight' l'altezza del campo text edit.
- * Val OUTPUT: TRUE se tutto ok, FALSE altrimenti.
- *
- *************************************************************************/
- int CGestisciElOrd::InitData(short fontNum, short fontSize, Boolean hasScroll)
- {
- const short fieldNumWidth = 20;
- CdataDescRec **descPtr = NULL;
- GrafPtr port;
- short lineHeight = 0;
- short fontAscent = 0;
- short right, i, j;
- short iType; // usati per settare i dati del DLOG
- Rect iRect;
- Handle iHandle;
- TEStyleRec **theStyle;
-
- HLock((Handle)descField);
- descPtr = *descField;
- GetDItem(theDialog, TEitem, &iType, &iHandle, &iRect);
- right = iRect.right;
- if (hasNumberField)
- {
- iRect.right = iRect.left + fieldNumWidth; // il campo numerazione è largo 'fieldNumWidth' pixel.
- numerazione = new CGestisci_TE;
- if (numerazione == NULL ||
- numerazione->IGestisci_TE(theDialog, 0, iRect, &backGround,
- fontNum, fontSize, false, false, true, false, 0, false, false, false))
- {
- SetErrorData(kErrOutMemory, 0, "CGestisciElOrd::InitData", "CGestisciElOrd.cp", "errore durante la numerazione");
- HUnlock((Handle)descField);
- return(true);
- }
- numerazione->overBox = false;
- iRect.left = iRect.left + fieldNumWidth + 1; // lascio un pixel tra i due campi.
- theStyle = GetStylHandle(numerazione->edit);
- lineHeight = (**(**theStyle).styleTab).stHeight;
- fontAscent = (**(**theStyle).styleTab).stAscent;
- iRect.left = iRect.right + 1;
- }
- for (i = 1; i < nField; i++, descPtr++)
- {
- iRect.right = iRect.left + (**descPtr).dim; // il campo numerazione è largo 'fieldNumWidth' pixel.
- (**descPtr).TEH = new CGestisci_TE;
- if ((**descPtr).TEH == NULL ||
- (**descPtr).TEH->IGestisci_TE(theDialog, 0, iRect, &backGround, (**descPtr).fontNum,
- (**descPtr).fontSize, false, false, true, (**descPtr).canModify, 0, false, false, false))
- {
- SetErrorData(kErrOutMemory, 0, "CGestisciElOrd::InitData",
- "CGestisciElOrd_v03.cp", "inizializzazione della struttura dati");
- HUnlock((Handle)descField);
- return(true);
- }
- (**descPtr).TEH->overBox = false;
- iRect.left = iRect.right + 1;
- }
- iRect.right = right;
- (**descPtr).TEH = new CGestisci_TE;
- if ((**descPtr).TEH == NULL ||
- (**descPtr).TEH->IGestisci_TE( theDialog, 0, iRect, &backGround, fontNum,
- fontSize, hasScroll, false, !hasScroll, (**descPtr).canModify, 0))
- {
- SetErrorData(kErrOutMemory, 0, "CGestisciElOrd::InitData",
- "CGestisciElOrd_v03.cp", "inizializzazione della struttura dati");
- HUnlock((Handle)descField);
- return(true);
- }
- (**descPtr).TEH->overBox = false;
- scrollTEH = (**descPtr).TEH;
- descPtr = *descField;
- GetPort(&port);
- SetPort(theDialog);
- for (i = 0; i < nField; i++, descPtr++)
- {
- if (lineHeight != 0)
- {
- short diffHeight;
-
- theStyle = GetStylHandle((**descPtr).TEH->edit);
- diffHeight = (**(**theStyle).styleTab).stHeight - lineHeight;
- if (diffHeight > 0)
- {
- lineHeight = (**(**theStyle).styleTab).stHeight;
- fontAscent = (**(**theStyle).styleTab).stAscent;
- if (hasNumberField)
- {
- theStyle = GetStylHandle(numerazione->edit);
- (**(**theStyle).styleTab).stHeight = lineHeight;
- (**(**theStyle).styleTab).stAscent = fontAscent;
- }
- descPtr = *descField;
- for (j = 0; j < i; j++, descPtr++)
- {
- theStyle = GetStylHandle((**descPtr).TEH->edit);
- (**(**theStyle).styleTab).stHeight = lineHeight;
- (**(**theStyle).styleTab).stAscent = fontAscent;
- }
- }
- else if (diffHeight < 0)
- {
- (**(**theStyle).styleTab).stHeight = lineHeight;
- (**(**theStyle).styleTab).stAscent = fontAscent;
- }
- }
- else
- {
- theStyle = GetStylHandle((**descPtr).TEH->edit);
- lineHeight = (**(**theStyle).styleTab).stHeight;
- fontAscent = (**(**theStyle).styleTab).stAscent;
- }
- }
- descPtr = *descField;
- linee = ((**(**descPtr).TEH->edit).viewRect.bottom -
- (**(**descPtr).TEH->edit).viewRect.top)/(**(**descPtr).TEH->edit).lineHeight;
- titoloScelto = noTitle;
- this->fieldNumWidth = fieldNumWidth;
- num = NULL; // il campo che contiene la numerazione.
- HUnlock((Handle)descField);
- TextFont(kStdFont);
- TextSize(kStdHeight);
- SetPort(port);
- return(false);
- }
-
- /*** inizializzaNumerazione()
- *
- * inizializza la numerazione.
- * per ora presuppone che il campo text edit sia vuoto
- * (la prima parte dell'array costituisce la mascera per la
- * seconda parte) !!!
- *
- **************************************************************/
- Boolean CGestisciElOrd::inizializzaNumerazione(void)
- {
- if (hasNumberField)
- {
- if (num != NULL)
- return(false);
-
- num = (short **)NewHandle(sizeof(short) * maxNumData * 2);
- if (num == NULL)
- {
- num = 0;
- return(false);
- }
- else
- azzeraNumerazione();
- return(false);
- }
- else
- return(true);
- }
-
- /*** azzeraNumerazione()
- *
- * Azzera l'array della numerazione.
- *
- ********************************************/
- void CGestisciElOrd::azzeraNumerazione(void)
- {
- if (hasNumberField)
- {
- short i;
- short *numVal;
- short *numMasc;
-
- if (num == NULL)
- return;
-
- HLock((Handle)num);
- numVal = *num;
- numMasc = &numVal[maxNumData];
- for (i = 0; i < maxNumData; i++)
- numVal[i] = numMasc[i] = noValue; // non ho inserito alcun dato
- HUnlock((Handle)num);
- actNumSet = 0;
- }
- }
-
- /*** sostituisciNumerazione()
- *
- * Presuppone che il campo textEdit sia vuoto.
- *
- **************************************************/
- void CGestisciElOrd::sostituisciNumerazione(void)
- {
- if (hasNumberField)
- {
- short i;
- short maxNum = (**(***descField).TEH->edit).nLines;
- short *numVal;
- short *numMasc;
- Cstring_P numero;
-
- if (num == NULL || numero.Istring_P())
- return;
-
- HLock((Handle)num);
- numVal = *num;
- numMasc = &numVal[maxNumData];
- numerazione->sostituisciTesto(&numero); // cancella tutto
- numero.Ctransfer(" \r");
- for (i = 0; i < maxNum; i++)
- numerazione->aggiungiTesto(&numero); // per ora suppongo che la lunghezza sia 2
- HUnlock((Handle)num);
- }
- }
-
- /*** scambiaValori(numSet)
- *
- * Presuppone che il campo textEdit sia vuoto.
- *
- **************************************************/
- void CGestisciElOrd::scambiaValori(void)
- {
- if (hasNumberField)
- {
- short *numVal;
- short *numMasc;
- short numSet = actNumSet;
- RGBColor BackColor;
- RGBColor BackGround = backGround;
-
- if (num == NULL)
- return;
-
- HLock((Handle)num);
- numVal = *num;
- numMasc = &numVal[maxNumData];
- GetBackColor(&BackColor);
- RGBBackColor(&BackGround);
- if (numVal[titoloScelto] != noValue)
- {
- short scambia = numVal[titoloScelto] + 1;
-
- numVal[numMasc[scambia - 1]] = -1;
- Riscrivi(numVal, numMasc[scambia - 1]);
- numMasc[scambia - 1] = -1;
-
- for (; scambia < numSet; scambia++)
- {
- numVal[numMasc[scambia]] -= 1;
- numMasc[scambia - 1] = numMasc[scambia];
- Riscrivi(numVal, numMasc[scambia]);
- }
- numSet -= 1; // numSet > 0 perchè ho già inserito un dato
- numMasc[numSet] = -1; // numSet >= 0 perchè ho già inserito un dato
- }
- else
- { // ho selezionato un campo vuoto
- numVal[titoloScelto] = numSet;
- numMasc[numSet] = titoloScelto;
- Riscrivi(numVal, titoloScelto);
- numSet += 1;
- }
- RGBBackColor(&BackColor);
- HUnlock((Handle)num);
- actNumSet = numSet;
- }
- }
-
- /*** scambiaValArray(array, pos1, pos2);
- *
- * Scambia i valori contenuti nell'array nelle posizioni "pos1" e "pos2".
- *
- *****************************************************************************/
- void CGestisciElOrd::scambiaValArray(short *array, short pos1, short pos2)
- {
- if (hasNumberField)
- {
- short scambio = array[pos1];
-
- array[pos1] = array[pos2];
- array[pos2] = scambio;
- }
- }
-
- /*** Riscrivi(num, pos)
- *
- * Riscrive i dati nella posizione "num".
- *
- *******************************************************/
- void CGestisciElOrd::Riscrivi(short *num, short pos)
- {
- if (hasNumberField)
- {
- char numero[10];
- short carPrecedente = (**numerazione->edit).lineStarts[pos];
-
- if (num[pos] >= 0)
- sprintf(numero, "%2i", num[pos] + 1); // per ora suppongo che la larghezza massima sia di due (vedi manuale del THINK per correzione)
- else
- sprintf(numero, " "); // per ora suppongo che la larghezza massima sia di due (vedi manuale del THINK per correzione)
-
- TESetSelect(carPrecedente, carPrecedente + 2, numerazione->edit); // ha supposto che la lunghezza massima sia 3
- TEDelete(numerazione->edit);
- TEInsert(numero, 2, numerazione->edit);
- }
- }
-
- /*** insertEl(num)
- *
- * Riscrive i dati nella posizione "num".
- *
- *******************************************************/
- void CGestisciElOrd::insertEl(short pos)
- {
- if (hasNumberField)
- {
- char numero[10];
- short carPrecedente = (**numerazione->edit).lineStarts[pos];
-
- TESetSelect(carPrecedente, carPrecedente, numerazione->edit); // ha supposto che la lunghezza massima sia 3
- sprintf(numero, " \r"); // per ora suppongo che la larghezza massima sia di due (vedi manuale del THINK per correzione)
- TEInsert(numero, 3, numerazione->edit);
- }
- }
-
- /*** CancellaEl(num)
- *
- * Riscrive i dati nella posizione "num".
- *
- *******************************************************/
- void CGestisciElOrd::CancellaEl(short pos)
- {
- if (hasNumberField)
- {
- short carPrecedente = (**numerazione->edit).lineStarts[pos];
-
- TESetSelect(carPrecedente, carPrecedente, numerazione->edit); // ha supposto che la lunghezza massima sia 3
- TEDelete(numerazione->edit);
- }
- }
-
-
- /*** "showActSel()"
- *
- * mostra la selezione attuale
- *
- ***/
- void CGestisciElOrd::showActSel(void)
- {
- TEHandle TEH = (***descField).TEH->edit;
- RGBColor BackColor;
- GrafPtr port;
- short carPrecedente = 0;
- CdataDescRec **descPtr = NULL;
- short i;
-
- GetPort(&port);
- SetPort((GrafPtr)theDialog);
- GetBackColor(&BackColor);
- RGBBackColor(&backGround);
- HLock((Handle)descField);
- descPtr = *descField;
- for (i = 0; i < nField; i++, descPtr++)
- {
- carPrecedente = (**(**descPtr).TEH->edit).lineStarts[titoloScelto];
- TESetSelect(carPrecedente, (**(**descPtr).TEH->edit).lineStarts[titoloScelto + 1],
- (**descPtr).TEH->edit);
- TEActivate((**descPtr).TEH->edit);
- }
- HUnlock((Handle)descField);
- RGBBackColor(&BackColor);
- SetPort(port);
- }
-
- /*** "gestClick(elOrdHdl, &theEvent)"
- *
- * Gestisce i "mouse Event" nel campo "ElOrd".
- * L' attivazione/disabilitazione del bottone ok
- * è gestita da questa procedura.
- *
- * Par INPUT: 'elOrdHdl' il puntatore alla struttura dati attuale,
- * 'theEvent' il puntatore al record dell'evento attuale.
- ************************************************************************/
- void CGestisciElOrd::gestClick(EventRecord *theEvent)
- {
- TEHandle TEH = (***descField).TEH->edit;
- RGBColor BackColor;
- short titoloScelto; // contiene una copia del dato globale
- short titoloAlto = GetCtlValue(scrollTEH->scroll);
- Boolean cambioNumerazione = false;
- GrafPtr port;
- short lineHeight;
- TEStyleRec **theStyle;
-
- GetPort(&port);
- SetPort((GrafPtr)theDialog);
- GetBackColor(&BackColor);
- RGBBackColor(&backGround);
- GlobalToLocal(&theEvent->where);
- if (PtInRect(theEvent->where, &(**scrollTEH->scroll).contrlRect))
- scrollTEH->clickInTE(theEvent);
- else
- {
- if( hasNumberField &&
- PtInRect(theEvent->where, &(**numerazione->edit).viewRect) )
- {
- cambioNumerazione = true;
-
- if (editLine != nil && canModify)
- {
- sostituisciDato();
- return;
- }
- }
- else
- {
- theStyle = GetStylHandle((***descField).TEH->edit);
- lineHeight = (**(**theStyle).styleTab).stHeight;
- titoloScelto = titoloAlto + (theEvent->where.v -
- (**TEH).viewRect.top)/lineHeight;
- if (titoloScelto != this->titoloScelto)
- {
- if (editLine != nil && canModify)
- {
- sostituisciDato();
- return;
- }
- }
-
-
- if (titoloScelto > (**TEH).nLines)
- this->titoloScelto = noTitle;
- else
- { // è stato selezionato "titoloScelto"
- if (titoloScelto == (**TEH).nLines && canModify == true &&
- !cambioNumerazione && (**TEH).nLines < maxNumData)
- {
- TEHandle TEH = (***descField).TEH->edit;
- long pos = (**TEH).lineStarts[titoloScelto];
- short *numVal;
- short *numMasc;
- short maxNum = (**TEH).nLines;
- char ret = '\r';
-
- TESetSelect(pos, pos, TEH);
- TEInsert(&ret, 1, TEH);
- this->titoloScelto = titoloScelto;
- HLock((Handle)num);
- numVal = *num;
- numMasc = &numVal[maxNumData];
- numMasc[maxNum] = numVal[maxNum] = noValue;
- HUnlock((Handle)num);
- insertEl(titoloScelto);
- }
- if (canModify == true)
- {
- this->titoloScelto = titoloScelto;
- modifyData(theEvent);
- }
- else if (titoloScelto < (**TEH).nLines)
- {
- short carPrecedente = 0;
- CdataDescRec **descPtr = NULL;
- short i;
-
- HLock((Handle)descField);
- descPtr = *descField;
- for (i = 0; i < nField; i++, descPtr++)
- {
- carPrecedente = (**(**descPtr).TEH->edit).lineStarts[titoloScelto];
- TESetSelect(carPrecedente, (**(**descPtr).TEH->edit).lineStarts[titoloScelto + 1],
- (**descPtr).TEH->edit);
- TEActivate((**descPtr).TEH->edit);
- }
- HUnlock((Handle)descField);
- this->titoloScelto = titoloScelto;
- if (cambioNumerazione)
- scambiaValori();
- }
- }
- }
- RGBBackColor(&BackColor);
- SetPort(port);
- }
- }
-
- /*** modifyData()
- *
- * Permette la modifica dei dati
- *
- ****************************************************/
- void CGestisciElOrd::modifyData(EventRecord *theEvent)
- {
- if (editLine == nil)
- {
- Rect editRect;
- TEHandle TEH = (***descField).TEH->edit;
- TEStyleRec **theStyle;
- short lineHeight;
- short titoloAlto = GetCtlValue(scrollTEH->scroll);
- long inizio, fine, len;
-
- theStyle = GetStylHandle(TEH);
- lineHeight = (**(**theStyle).styleTab).stHeight;
- editLine = new CGestisci_TE;
- if (editLine == NULL)
- return;
- editRect = (**TEH).viewRect;
- editRect.top += (titoloScelto - titoloAlto) * lineHeight;
- editRect.bottom = editRect.top + lineHeight;
- editLine->IGestisci_TE( theDialog, 0, editRect, &backGround,
- (**(***descField).TEH->edit).txFont,
- (**(***descField).TEH->edit).txSize,
- false, false, true, true, 0, false, false, false);
- editLine->canModify = true;
- inizio = (**TEH).lineStarts[titoloScelto];
- fine = (**TEH).lineStarts[titoloScelto + 1] - 1;
- len = fine - inizio;
- if (len > 0)
- {
- Cstring_P strRead;
- Ptr pText;
-
- strRead.Istring_P();
- HLock((**TEH).hText);
- pText = *(**TEH).hText;
- strRead.Copy(0, (short)len, &pText[inizio]);
- editLine->sostituisciTesto(&strRead);
- HUnlock((**TEH).hText);
- }
- editLine->attivaTesto(true, true);
- }
- else
- editLine->clickInTE(theEvent);
- }
-
- /*** sostituisciDato()
- *
- * Permette la modifica dei dati
- *
- ****************************************************/
- Boolean CGestisciElOrd::sostituisciDato(void)
- {
- Boolean cancellato = false;
-
- if (editLine != nil)
- {
- TEHandle TEH = (***descField).TEH->edit;
- char pt = '.';
- long inizio, fine, len;
-
- editLine->disattivaTesto();
- TEDeactivate(TEH);
- inizio = (**TEH).lineStarts[titoloScelto];
- fine = (**TEH).lineStarts[titoloScelto + 1];
- TESetSelect(inizio, fine, TEH);
- TEDelete(TEH);
- len = (**(*editLine).edit).teLength;
- if (len > 1 || (len == 1 && (**(**(*editLine).edit).hText) != '.'))
- {
- char *strRead;
-
- HLock((**(*editLine).edit).hText);
- strRead = *(**(*editLine).edit).hText;
- TEInsert(strRead, len, TEH);
- if (strRead[len - 1] != '.')
- {
- TEInsert(&pt, 1L, TEH);
- len++;
- }
- pt = '\r';
- TEInsert(&pt, 1L, TEH);
- HUnlock((**(*editLine).edit).hText);
- }
- else
- {
- short *numVal;
- short *numMasc;
- short i, maxNum = (**TEH).nLines;
-
- HLock((Handle)num);
- numVal = *num;
- numMasc = &numVal[maxNumData];
- if (numVal[titoloScelto] != noValue)
- scambiaValori();
- CancellaEl(titoloScelto);
- for (i = titoloScelto; i < maxNum; i++)
- numVal[i] = numVal[i + 1];
- for (i = 0; i < maxNum; i++)
- if (numMasc[i] >= titoloScelto)
- numMasc[i] -= 1;
- titoloScelto = noTitle;
- TEDeactivate(TEH);
- HUnlock((Handle)num);
- cancellato = true;
- }
- delete editLine;
- editLine = nil;
- }
- return(cancellato);
- }
-
- /*** inserisce un carattere
- *
- ************************************/
- void CGestisciElOrd::insertChar(EventRecord *theEvent)
- {
- if (editLine != nil)
- editLine->keyStroke(theEvent);
- }
-
- /*** "listaFont(elOrdHdl)"
- *
- * Gestisce l'updateEvt nei campi definiti come "user"
- *
- * Par INPUT: 'elOrdHdl' il puntatore alla struttura dati attuale,
- *
- ************************************************************************/
- void CGestisciElOrd::updateEvt(void)
- {
- CdataDescRec **descPtr = NULL;
- GrafPtr port;
- Rect viewRect;
- short fontSize, fontNum;
- short i;
-
- GetPort(&port);
- SetPort(theDialog);
- fontSize = theDialog->txSize;
- fontNum = theDialog->txFont;
- HLock((Handle)descField);
- descPtr = *descField;
- for (i = 0; i < nField; i++, descPtr++)
- {
- TextFont((**descPtr).fontTitle);
- TextSize((**descPtr).sizeTitle);
- viewRect = (**(**descPtr).TEH->edit).viewRect;
- MoveTo(viewRect.left + 4, viewRect.top - 2);
- DrawString((**descPtr).title);
- (**descPtr).TEH->updateEvt();
- }
- TextFont(fontNum);
- TextSize(fontSize);
- HUnlock((Handle)descField);
- if (editLine != NULL)
- editLine->updateEvt();
- SetPort(port);
- }
-
- /*** "disabilita(elOrdHdl, &theEvent)"
- *
- * Gestisce i click nella scroll Bar.
- *
- * Non tratta il doppio click e lo scroll mentre il bottone é abbassato.
- *
- *****************************************************************************/
- void CGestisciElOrd::disabilita()
- {
- if (canModify && editLine != NULL)
- sostituisciDato();
- else
- {
- CdataDescRec **descPtr = NULL;
- short i;
-
- HLock((Handle)descField);
- descPtr = *descField;
- for (i = 0; i < nField; i++, descPtr++)
- (**descPtr).TEH->disattivaTesto();
- HUnlock((Handle)descField);
- }
- }
-
- /*** "abilita(elOrdHdl, &theEvent)"
- *
- * Gestisce i click nella scroll Bar.
- *
- * Non tratta il doppio click e lo scroll mentre il bottone é abbassato.
- *
- * Par INPUT: 'elOrdHdl' il puntatore alla struttura dati attuale,
- * 'theEvent' il puntatore al record dell'evento attuale;
- *****************************************************************************/
- void CGestisciElOrd::abilita(void)
- {
- ;
- }
-
- /*** "KeyDown(elOrdHdl, &theEvent)"
- *
- * Gestisce i click nella scroll Bar.
- *
- * Non tratta il doppio click e lo scroll mentre il bottone é abbassato.
- *
- * Par INPUT: 'elOrdHdl' il puntatore alla struttura dati attuale,
- * 'theEvent' il puntatore al record dell'evento attuale;
- *****************************************************************************/
- Boolean CGestisciElOrd::KeyDown(EventRecord *theEvent)
- {
- if (canModify && editLine != nil)
- {
- editLine->keyStroke(theEvent);
- return(false);
- }
- else
- {
- register char theChar = (char)((theEvent->message & keyCodeMask) >> 8);
- const char kUp = 0x7E;
- const char kDown = 0x7D;
- short scrollF = 0;
-
- switch(theChar)
- {
- case kUp:
- scrollF = +1;
- titoloScelto = (titoloScelto > 0) ? titoloScelto - 1 : 0;
- break;
- case kDown:
- scrollF = -1;
- titoloScelto = (titoloScelto < (**(***descField).TEH->edit).nLines -1) ? titoloScelto + 1
- : (**(***descField).TEH->edit).nLines - 1;
- break;
- }
- if (scrollF != 0)
- {
- CdataDescRec **descPtr;
- short i;
-
- if (numerazione != NULL)
- numerazione->scrollFactor(scrollF);
- HLock((Handle)descField);
- descPtr = *descField;
- for (i = 0; i < nField; i++, descPtr++)
- (**descPtr).TEH->scrollFactor(scrollF);
- showActSel();
- return(false);
- }
- }
- return(true);
- }
-
- /*** "TEidle(elOrdHdl)"
- *
- * Gestisce i click nella scroll Bar.
- *
- * Gestisce il blink sul campo selezionato.
- *
- * Par INPUT: 'elOrdHdl' il puntatore alla struttura dati attuale,
- *****************************************************************************/
- void CGestisciElOrd::TEidle(void)
- {
- if (editLine != NULL)
- editLine->blink();
- }
-
- /****
- * sostituisciTesto_gestDLOG(elOrdHdl, str, len);
- *
- * inserisce del testo nel textEdit corrente
- *
- ***/
- Boolean CGestisciElOrd::sostituisciTesto(short nEl, Cstring_P *dataStr)
- {
- if (nEl == nField)
- {
- CdataDescRec **descPtr = NULL;
- short i;
-
- HLock((Handle)descField);
- descPtr = *descField;
- HLock((Handle)dataStr);
- for (i = 0; i < nField; i++, descPtr++, dataStr++)
- (**descPtr).TEH->sostituisciTesto(dataStr);
- HUnlock((Handle)descField);
- sostituisciNumerazione();
- return(false);
- }
- else
- return(true);
- }
-
- /****
- * cancellaTesto(elOrdHdl);
- *
- * inserisce del testo nel textEdit corrente
- *
- ***/
- Boolean CGestisciElOrd::cancellaTesto(void)
- {
- CdataDescRec **descPtr = NULL;
- Cstring_P str;
- short i;
-
- str.Istring_P();
- HLock((Handle)descField);
- descPtr = *descField;
- for (i = 0; i < nField; i++, descPtr++)
- (**descPtr).TEH->sostituisciTesto(&str);
- HUnlock((Handle)descField);
- sostituisciNumerazione();
- return(false);
- }
-
- /****
- * aggiungiTesto(elOrdHdl, str, len);
- *
- * inserisce del testo nel textEdit corrente
- *
- ***/
- Boolean CGestisciElOrd::aggiungiTesto(short nEl, Cstring_P *dataStr)
- {
- if (nEl == nField)
- {
- Cstring_P str2;
- CdataDescRec **descPtr = NULL;
- short i;
-
- str2.Istring_P(2);
- str2.Ctransfer("\r");
- HLock((Handle)descField);
- descPtr = *descField;
- for (i = 0; i < nField; i++, descPtr++, dataStr++)
- {
- (**descPtr).TEH->aggiungiTesto(dataStr);
- (**descPtr).TEH->aggiungiTesto(&str2);
- }
- HUnlock((Handle)descField);
- sostituisciNumerazione();
- return(false);
- }
- else
- return(true);
- }
-